<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>单据查询</title>
<%@ include file="/WEB-INF/pages/common/frameCommonJs.jsp"  %>
<style type="text/css">
#fm{
	margin:0;
	padding:10px 30px;
}
.ftitle{
	font-size:14px;
	font-weight:bold;
	color:#666;
	padding:5px 0;
	margin-bottom:10px;
	border-bottom:1px solid #ccc;
}
.fitem{
	margin-bottom:5px;
}
.fitem label{
	display:inline-block;
	width:80px;
}
</style>
<script>
   var getClassUrl = "<%=request.getContextPath()%>/organization/getAllOrganizationClassJson.action";
   // 往来单位内容读取开始
   $(function(){
   	  // 单据类别
   	  $("#searchVoucherCondition\\.voucherType").combobox({  
		    url:'<%=request.getContextPath()%>/searchcenter/getVoucherTypes.action',  
		    valueField:'id',  
		    textField:'text',
		    required:true,
	  });  	
	  
	  // 已审核未审核状态
	  $("#searchVoucherCondition\\.isverity").combobox({  
		    url:'<%=request.getContextPath()%>/searchcenter/getVoucherVerityTypes.action',  
		    valueField:'id',  
		    textField:'text'
	  }); 
	  // 查询结果表格
	  $('#searchResults').datagrid({
		iconCls:'icon-save',
		nowrap: false,
		striped: true,
		collapsible:true,
		url:'<%=request.getContextPath()%>/searchcenter/searchVoucher.action',
		sortName: 'code',
		sortOrder: 'desc',
		remoteSort: false,
		idField:'code',
		singleSelect:true,
		columns:[[
			{field:'id',title:'id',width:150,edit:false,hidden:true},
			{field:'voucherNo',title:'单据编号',width:100,edit:false},
			/* {field:'no',title:'自定义编号',width:120,edit:false}, */
			{field:'org',title:'往来单位',width:140,edit:false},
			{field:'wareHouse',title:'入库仓库',width:140,edit:false},
			{field:'transactionAmount',title:'成交金额(元)',width:120,rowspan:2,sortable:true,edit:false,align:'right',
				formatter:function(value,row,index) {
					return row.transactionAmount.toFixed(2);
				}
			},
			/* {field:'receiveAmount',title:'收款金额(元)',width:150,rowspan:2,edit:false,align:'right',sortable:true}, */
			{field:'dateTime',title:'日期',width:100,editor:'numberbox',sortable:true},
			{field:'isverity',title:'状态',width:50,editor:'numberbox',
				formatter:function(value,row,index) {
					if(row.isverity=='verityed'){
						return "已审核";
					}else if (row.isverity=='cancel'){
						return "<font color='brown'>已作废</font>";				
					}
					else{
						return "<font color='red'>未审核</font>";
					}
				}	
			},
			/* {field:'note',title:'备注',width:200,editor:'numberbox'}, */
			{field:'action',title:'操作',width:80,editor:'numberbox', 
				formatter:function(value,row,index){
				   var s = "";
				   if(row.type=="warehouse"){
				   		s = '<a href="javascript:parent.addTabDirect(\'进货入库单\',\'<%=request.getContextPath()%>/voucher/toAddWareHouseVoucher.action?id=' + row.id + '\')">详细</a>';
				   }
				   if(row.type=="delivery"){
				   		s = '<a href="javascript:parent.addTabDirect(\'销售出库单\',\'<%=request.getContextPath()%>/voucher/toAddDeliveryVoucher.action?id=' + row.id + '\')">详细</a>';
				   }
				   if(row.type=="returndelivery"){
				   		s = '<a href="javascript:parent.addTabDirect(\'销售退货单\',\'<%=request.getContextPath()%>/voucher/toAddReturnDeliveryVoucher.action?id=' + row.id + '\')">详细</a>';
				   }
				   if(row.type=="returnwarehouse"){
				   		s = '<a href="javascript:parent.addTabDirect(\'进货退货单\',\'<%=request.getContextPath()%>/voucher/toAddReturnWareHouseVoucher.action?id=' + row.id + '\')">详细</a>';
				   }
                   return s;
                }
            }
		]],
		pageSize:15,  
        pageList:[5,10,15,20],  
        fitColumns: true,  
        pagination:true,
		rownumbers:true,
		onBeforeEdit:function(index,row){
            row.editing = true;
            $('#selectedPros').datagrid('refreshRow', index);
            editcount++;
        },
        onAfterEdit:function(index,row){
            row.editing = false;
            $('#selectedPros').datagrid('refreshRow', index);
            editcount--;
        },
        onCancelEdit:function(index,row){
            row.editing = false;
            $('#selectedPros').datagrid('refreshRow', index);
            editcount--;
        }
	  });
   });
   function openOrg(){
   		var title = "往来单位选择";
   		$('#orgDlg').dialog('open').dialog('setTitle',title);  
   }
   function openWareHouse(){
   		var title = "入库仓库选择";
   		$('#wareHouseDlg').dialog('open').dialog('setTitle',title);  
   }
   function selectOrg(){
   		var node = $('#orgs').datagrid("getSelected");
   		$("#orgname").val(node.name);
   		$("#searchVoucherCondition\\.orgId").val(node.id);
   		$('#orgDlg').dialog('close');
   }
   function selectWareHouse(){
   		var node = $('#wars').datagrid("getSelected");
   		$("#wv\\.wareHouse\\.name").val(node.name);
   		$("#searchVoucherCondition\\.orgId").val(node.id);
   		$('#wareHouseDlg').dialog('close');
   }
   function searchVoucher(){
	    if(!$("#searchVoucherFm").form('validate')){
	    	return;
	    }  
   		var voucherNo = $("#searchVoucherCondition\\.voucherNo").val();
   		var voucherType = $("#searchVoucherCondition\\.voucherType").combobox('getValue');
   		var orgId = $("#searchVoucherCondition\\.orgId").val();
   		var stime = $("input[name=stime]").val();
   		var etime = $("input[name=etime]").val();
   		var isverity = $("#searchVoucherCondition\\.isverity").combobox('getValue');
   		$('#searchResults').datagrid('reload',{'searchVoucherCondition.stime':stime,'searchVoucherCondition.etime':etime,'searchVoucherCondition.voucherNo':voucherNo,'searchVoucherCondition.voucherType':voucherType,'searchVoucherCondition.orgId':orgId,'searchVoucherCondition.isverity':isverity})
   		$('#searchResults').datagrid({pageNumber:1});
   }
</script>
</head>
<body class="easyui-layout" >

<div region="north" title="单据查询" split="true" style="height:160px;">
	<div id="tb" class="datagrid-toolbar">  
	    <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="javascript:searchVoucher()">查询</a>  
	</div>
	<center>
	<form id="searchVoucherFm" method="post">  
	<table style="font-size:12px;padding:10px;0px;0px;0px;" border="0">
		<tr>
			<td>
				单据类别
			</td>
			<td>
 				<select type="text" id="searchVoucherCondition.voucherType" name="searchVoucherCondition.voucherType"  style="width:100px"></select>
 				&nbsp;&nbsp;
 			</td>
			<td>
				往来单位
			</td>
			<td>
				<input type="text" id="orgname" name="orgname" onclick="openOrg()" readonly="readonly" class="easyui-validatebox" style="PADDING-LEFT: 20px;BACKGROUND-IMAGE: url(<%=request.getContextPath()%>/images/note_add.png); BACKGROUND-REPEAT: no-repeat;cursor:pointer;" size="17" /><input type="hidden" id="searchVoucherCondition.orgId" name="searchVoucherCondition.orgId" />
			</td>
			<td>
				单据编号
			</td>
			<td>
				<input type="text" id="searchVoucherCondition.voucherNo" name="searchVoucherCondition.voucherNo" class="easyui-validatebox"  />
			</td>
 		</tr>
 		<tr>
 			<td>单据日期</td>
 			<td colspan="5" align="left">
				<input class="easyui-datebox" name="stime" id="stime" style="width:100px" readonly="readonly"> ~ <input class="easyui-datebox" name="etime" id="etime" style="width:100px" readonly="readonly">
 				&nbsp;
 				&nbsp;
 				状态
 				<select type="text" id="searchVoucherCondition.isverity" name="searchVoucherCondition.isverity" style="width:80px" /></select>
 			</td>
 		</tr>
 		<input type="hidden" name="products" id="products" />
	</table>
	</form>
	</center>
</div>
<div region="center" title="查询结果" split="true" style="height:430px">
	<table id="searchResults" name="searchResults"></table>
</div>
<%@ include file="/WEB-INF/pages/common/organizationSelect.jsp"  %>
</body>
</html>